package com.gin.kotlin.no_gay_alliance.activity

import android.content.Context
import android.content.Intent
import com.gin.kotlin.no_gay_alliance.adapter.SubForumAdapter
import com.gin.kotlin.no_gay_alliance.base.AbstractBindingActivity
import com.gin.kotlin.no_gay_alliance.databinding.ActivitySubForumsBinding
import com.gin.kotlin.no_gay_alliance.model.SubForumModel

class SubForumActivity : AbstractBindingActivity<ActivitySubForumsBinding>(){
    private var forumId: Long = 0
    private lateinit var adapter: SubForumAdapter
    private lateinit var subForums: ArrayList<SubForumModel>

    override fun onCreate() {
        val b = this.b ?: return
        this.adapter = SubForumAdapter(this, handler!!, this.subForums)
        this.adapter.forumId = this.forumId
        b.recyclerView.adapter = this.adapter

    }

    override fun handleIntent(intent: Intent) {
        this.subForums = parseArgumentList(intent, SubForumModel::class.java.simpleName, SubForumModel::class.java)
        this.forumId = intent.getLongExtra(KEY_FORUM_ID, 0L).takeIf { it!=0L } ?:throw RuntimeException("必须提供版面ID")
    }

    companion object {
        const val KEY_FORUM_ID = "fid"

        @JvmStatic
        fun start(context: Context, forumId: Long, data: List<SubForumModel> = listOf()) {
            val starter = Intent(context, SubForumActivity::class.java)
                .putExtra(KEY_FORUM_ID, forumId)
                .putParcelableArrayListExtra(SubForumModel::class.java.simpleName, arrayListOf(* data.toTypedArray()))
            context.startActivity(starter)
        }
    }

}